package org.jimmy.tang.designpattern.behavior.visitor;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author jimmy
 * 
 */
public class ConcreteVisitor implements Visitor {

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.visitor.Visitor#visitString(org.jimmy.tang.designpattern.behavior.visitor.StringElement)
     */
    @Override
    public void visitString(StringElement stringE) {
        System.out.println(stringE.getSe());

    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.visitor.Visitor#visitFloat(org.jimmy.tang.designpattern.behavior.visitor.FloatElement)
     */
    @Override
    public void visitFloat(FloatElement floatE) {
        System.out.println(floatE.getFe());

    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.visitor.Visitor#visitCollection(java.util.Collection)
     */
    @Override
    public void visitCollection(Collection<?> collection) {
        Iterator<?> iterator = collection.iterator();
        while (iterator.hasNext()) {
            Object o = iterator.next();
            if (o instanceof Visitable) {
                ((Visitable) o).accept(this);
            }
        }

    }

}
